@*
    For more information on enabling MVC for empty projects, visit https://go.microsoft.com/fwlink/?LinkID=397860
*@
@{
    Layout = null;
}
<!DOCTYPE html>
<html lang="zh-CN">

<head>
    <meta charset="UTF-8">
    <title>医院数据仪表盘</title>
    <script src="https://cdn.jsdelivr.net/npm/chart.js"></script>
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>医院数据仪表盘</title>
    <script src="~/lib/jquery/dist/jquery.min.js"></script>
    <link rel="stylesheet" href="https://unpkg.com/layui@2.8.15/dist/css/layui.css">
    <link rel="stylesheet" href="https://cdn.staticfile.org/layui/2.8.12/css/layui.min.css">
    <style>
        body {
            padding: 20px;
            background-color: #f4f4f4;
        }

        .layui-card {
            box-shadow: 0 0 5px rgba(0, 0, 0, 0.1);
            border: none;
            border-radius: 5px;
            overflow: hidden;
        }

        .layui-card-header {
            background-color: #009688;
            color: white;
            padding: 10px;
            font-size: 18px;
            font-weight: 600;
        }

        /* 图表容器样式 */
        .chart-container {
            margin-bottom: 20px;
        }

        #dataOverviewChart {
            height: 300px;
            width: 100%;
        }

        .layui-table {
            width: 100%;
            border-collapse: collapse;
        }

            .layui-table th,
            .layui-table td {
                padding: 10px;
                text-align: center;
                border: 1px solid #e6e6e6;
            }

            .layui-table th {
                background-color: #f2f2f2;
            }

        .simplified-table {
            margin-top: 20px;
        }
    </style>
</head>

<body>
    <div class="layui-container">
        <!-- 顶部统计数据 -->
        <div class="layui-row layui-col-space10">
            <div class="layui-col-md3">
                <div class="layui-card">
                    <div class="layui-card-header">
                        <i class="layui-icon layui-icon-home"></i> 今日预约人数
                    </div>
                    <div class="layui-card-body">
                        <h1 style="margin: 0; font-size: 24px;" id="pageCount"></h1>
                    </div>
                </div>
            </div>
            <div class="layui-col-md3">
                <div class="layui-card">
                    <div class="layui-card-header">
                        <i class="layui-icon layui-icon-video"></i> 今日挂号人数
                    </div>
                    <div class="layui-card-body">
                        <h1 style="margin: 0; font-size: 24px;" id="Sigcount"></h1>
                    </div>
                </div>
            </div>
            <div class="layui-col-md3">
                <div class="layui-card">
                    <div class="layui-card-header">
                        <i class="layui-icon layui-icon-user"></i> 今日门诊充值总额
                    </div>
                    <div class="layui-card-body">
                        <h1 style="margin: 0; font-size: 24px;" id="pending">5060</h1>
                    </div>
                </div>
            </div>
            <div class="layui-col-md3">
                <div class="layui-card">
                    <div class="layui-card-header">
                        <i class="layui-icon layui-icon-like"></i> 今日门诊消费总额
                    </div>
                    <div class="layui-card-body">
                        <h1 style="margin: 0; font-size: 24px;">4560</h1>
                    </div>
                </div>
            </div>
            <div class="layui-col-md3">
                <div class="layui-card">
                    <div class="layui-card-header">
                        <i class="layui-icon layui-icon-like"></i> 近7日挂号预约情况
                    </div>
                    <div class="layui-card-body">
                        <canvas id="myLineChart" width="200" height="200"></canvas>
                    </div>
                </div>
            </div>

            <div class="layui-col-md3">
                <div class="layui-card">
                    <div class="layui-card-header">
                        <i class="layui-icon layui-icon-like"></i> 近7日门诊充值趋势
                    </div>
                    <div class="layui-card-body">
                        <canvas id="chongzhi" width="200" height="200"></canvas>
                    </div>
                </div>
            </div>
        </div>
    </div>

    <!-- 简化后的表格 -->
    <div class="layui-container simplified-table">
        <table class="layui-table" lay-data="{url:'https://localhost:7171/api/Registration/GetRegistration', page:true, id:'test', limit: 10, limits:[5,10,15,20], request: {pageName: 'pageIndex', limitName: 'pageSize'}}" lay-filter="test">
            <thead>
                <tr>
                    <th lay-data="{field:'patientName', width:150, title:'患者姓名'}"></th>
                    <th lay-data="{field:'phone', width:150, title:'手机号码'}"></th>
                    <th lay-data="{field:'deparName', width:200, title:'科室名称'}"></th>
                    <th lay-data="{field:'registrationfee', width:120, title:'挂号费'}"></th>
                    <th lay-data="{field:'registrationTime', width:200, title:'挂号时间', sort:true}"></th>
                </tr>
            </thead>
        </table>
    </div>
    <div id="hot-departments"></div>
    <div id="hot-doctors"></div>

    @* 日挂号预约情况 *@
    <script>
        // 模拟从服务器获取的数据
        var dynamicData = {
            labels: ['5.4', '5.5', '5.6', '5.7', '5.8', '5.9'],
            datasets: [{
                label: '销售额',
                data: [100, 200, 300, 400, 500, 600],
                borderColor: 'rgba(100, 300, 100, 600)',
                borderWidth: 1,
                fill: false
            }]
        };

        // 创建折线图
        var ctx = document.getElementById('chongzhi').getContext('2d');
        var chongzhi = new Chart(ctx, {
            type: 'line',
            data: dynamicData,
            options: {
                responsive: true,
                scales: {
                    x: {
                        display: true,
                        title: {
                            display: true,
                            text: '月份'
                        }
                    },
                    y: {
                        display: true,
                        title: {
                            display: true,
                            text: '销售额'
                        }
                    }
                }
            }
        });
    </script>
    @* 日门诊充值趋势 *@
    <script>
        // 模拟从服务器获取的数据
        var dynamicData = {
            labels: ['5.4', '5.5', '5.6', '5.7', '5.8', '5.9'],
            datasets: [{
                label: '销售额',
                data: [65, 59, 80, 81, 56, 55],
                borderColor: 'rgba(75, 192, 192, 1)',
                borderWidth: 1,
                fill: false
            }]
        };

        // 创建折线图
        var ctx = document.getElementById('myLineChart').getContext('2d');
        var myLineChart = new Chart(ctx, {
            type: 'line',
            data: dynamicData,
            options: {
                responsive: true,
                scales: {
                    x: {
                        display: true,
                        title: {
                            display: true,
                            text: '月份'
                        }
                    },
                    y: {
                        display: true,
                        title: {
                            display: true,
                            text: '销售额'
                        }
                    }
                }
            }
        });
    </script>

    <script src="https://cdn.staticfile.org/layui/2.8.12/layui.min.js"></script>
    <script src="https://cdn.staticfile.org/echarts/5.4.3/echarts.min.js"></script>
    <script src="https://cdn.staticfile.org/axios/1.4.0/axios.min.js"></script>
    <script>
        $(function () {
            // 同时获取三个数据（新增待处理服务量的获取）
            Promise.all([getUserData(), getSignedData(), getPendingData()])
                .then(() => renderChart())
                .catch(console.error);
        });

        var residentData = {
            total: 0,       // 居民总数量
            signed: 0,      // 签约居民数量
            pending: 0      // 待处理服务量（修正变量名）
        };
        // 1. 今日预约人数
        function getUserData() {
           // url: `@ViewBag.BaseUrl/T5/Registration/GetRegistration`,
            return axios.get('https://localhost:7171/api/Registration/GetRegistration')
                .then(res => {
                    console.log("888",res.data);
                    const dataArray1 = res.data.count;
                    $("#pageCount").text(dataArray1);
                });
        }

        // 2.  今日挂号人数
        function getSignedData() {
            // url: `@ViewBag.BaseUrl/T5/Registration/GetRegistration`,
            return axios.get('https://localhost:7171/api/Registration/GetRegistration')
                .then(res => {
                    console.log("123",res.data);
                    const dataArray = res.data.count;
                    $("#Sigcount").text(dataArray);
                });
        }

        // 3. 今日门诊充值总额
        function getPendingData() {
            return axios.get('https://localhost:7125/api/Serves/GetServe') // 假设接口正确
                .then(res => {
                    residentData.pending = res.data.data.length || 0; // 新增默认值避免undefined
                    $("#pending").text(residentData.pending); // 正确赋值给pending
                });
        }

        // 使用Layui表格
        layui.use('table', function(){
            var table = layui.table;

            // 渲染表格
            table.render({
                elem: '#test',
                //url: 'https://localhost:7171/api/Registration/GetRegistration',
                url: `@ViewBag.BaseUrl/T5/Registration/GetRegistration`,
                page: true,
                request: {
                    pageName: 'pageIndex',
                    limitName: 'pageSize'
                },
                limit: 10,
                limits: [5, 10, 15, 20],
                cols: [[
                    {field: 'patientName', title: '患者姓名', width: 150},
                    {field: 'phone', title: '手机号码', width: 150},
                    {field: 'deparName', title: '科室名称', width: 200},
                    {field: 'registrationfee', title: '挂号费', width: 120},
                    {field: 'registrationTime', title: '挂号时间', width: 200, sort: true}
                ]],
                initSort: {
                    field: 'registrationTime', // 按挂号时间排序
                    type: 'desc' // 降序排列
                }
            });
        });


          // 使用Layui表格
        layui.use('departments', function(){
            var table = layui.table;

            // 渲染表格
            table.render({
                elem: '#test',
                //url: 'https://localhost:7171/api/Registration/GetRegistration',
                url: `@ViewBag.BaseUrl/T5/Registration/GetRegistration`,
                page: true,
                request: {
                    pageName: 'pageIndex',
                    limitName: 'pageSize'
                },
                limit: 10,
                limits: [5, 10, 15, 20],
                cols: [[
                    {field: 'deparName', title: '科室名称', width: 200},
                    {field: 'registrationfee', title: '挂号费', width: 120},
                ]],
            });
        });













    </script>
</body>
</html>